<?php
header("content-type:text/html;charset=utf8");

$username = $_POST["username"];
$pwd = $_POST["pwd"];
$email = $_POST["email"];
$tel = $_POST["tel"];
//连接数据库
$con = mysqli_connect('localhost','root','root','xiaomi');
$res = mysqli_query($con,"select * from user where username='$username'");
$row = mysqli_fetch_assoc($res);
if($row){
    $arr = [
        "meta"=>[
            "status"=>3,
            "msg"=>"用户名被占用！"
        ]
    ];
}else{
    $bool = mysqli_query($con,"insert user(username,pwd,email,tel) values('$username','$pwd','$email','$tel')");
    if($bool){
        $arr = [
            "meta"=>[
                "status"=>1,
                "msg"=>"注册成功"
            ]
        ];
    }else{
        $arr = [
            "meta"=>[
                "status"=>2,
                "msg"=>"注册失败"
            ]
        ];
    }
}
echo json_encode($arr);